package org.tiangou.test;

import org.tiangou.entity.User;
import org.tiangou.utils.JwtUtil;

import java.util.HashMap;
import java.util.Map;

public class MainTest02 {

    private static void create() {
        // 定义一个Map对象，用于封装相关的令牌
        Map<String, Object> map = new HashMap<>();

        // 创建一个用户对象
        User user = new User("petter",null,"男",18) ;

        // 封装数据
        map.put("userInfo",user) ;

        // 创建jwt令牌字符串，有效时间：1天
        String token = JwtUtil.createToken(map,1 * 24 * 60 * 60 * 1000) ;
        System.out.println(token);
    }


    public static void main(String[] args) throws Exception {
        // 1.创建 Token
        // create() ;

        // 2.验证　Token
        // JwtUtil.verify("eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySW5mbyI6eyJuYW1lIjoicGV0dGVyIiwicGFzcyI6bnVsbCwic2V4Ijoi55S3IiwiYWdlIjoxOH0sInN1YiI6IkpXVF9BVVRIIiwiaXNzIjoiZWR1Lm5mIiwiZXhwIjoxNjM4MzI4Mjk2LCJpYXQiOjE2MzgyNDE4OTZ9.ZJtzoyndCbCj9rINQVvhyPqLhJU_Cyx0xiMnACJ8K2w");

        // 3.获取 Token中的信息
        Map<String,Object> map = JwtUtil.getPayload("eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySW5mbyI6eyJuYW1lIjoicGV0dGVyIiwicGFzcyI6bnVsbCwic2V4Ijoi55S3IiwiYWdlIjoxOH0sInN1YiI6IkpXVF9BVVRIIiwiaXNzIjoiZWR1Lm5mIiwiZXhwIjoxNjM4MzI4Mjk2LCJpYXQiOjE2MzgyNDE4OTZ9.ZJtzoyndCbCj9rINQVvhyPqLhJU_Cyx0xiMnACJ8K2w", "userInfo", Map.class);

        // System.out.println(map);
        System.out.println(map.get("name"));
        System.out.println(map.get("sex"));
        System.out.println(map.get("age"));

    }
}
